package com.houdoudou.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnFactory {

    public static final String url = "jdbc:mysql://127.0.0.1/houdoudb";  
    public static final String name = "com.mysql.jdbc.Driver";  
    public static final String user = "root";  
    public static final String password = "123456"; 
    
 public static  Connection  getConn(){
	   Connection conn = null;
	   try {
		Class.forName(name);
		 conn = DriverManager.getConnection(url, user, password);//获取连接 
		 System.out.println("-------------创建了数据库连接--------------- "+conn);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}//指定连接类型  
      
	   return conn;
    }

 public static void closeStatment(PreparedStatement pstm,Statement stm, ResultSet rs){
	 
	 
		try {
			if(rs!=null) rs.close();
			 if(stm!=null) stm.close();
			 if(pstm!=null) pstm.close();
			 		 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
 
 public static void closeConn(Connection conn){
	 
	 
		try {
			
			 if(conn!=null) {
				 System.out.println("-------------关闭数据库连接----------- "+conn);
				 conn.close();			 
			}			 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       }
}
